//
//  FeedbackVC.m
//  jzyStudents
//
//  Created by 任辰东 on 2022/9/22.
//

#import "FeedbackVC.h"
#import "RCDTextFeidView.h"
#import "RCDCornerBtn.h"
#import "MineApis.h"

@interface FeedbackVC ()
@property (nonatomic, strong) RCDTextFeidView *feedBackView;
@property (nonatomic, strong) RCDCornerBtn *submitBtn;
@end

@implementation FeedbackVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"用户反馈";
    
    WeakSelf
    [self.submitBtn setClickBlock:^(UIButton * _Nonnull btn) {
       StrongSelf
        [self submit];
        
    }];
}

- (void)submit
{
    [self.view endEditing:YES];
    if (IsEmpty(self.feedBackView.model.content)) {
        [self showTextHUDWithMessage:@"请填写您的建议或意见"];
        return;
    }

    NSDictionary *parms = @{
        @"student_id":[GVUserDefaults standardUserDefaults].student_id,
        @"feedback_info":self.feedBackView.model.content
    };

    WeakSelf
    [self showLoadingHUDWithMessage:nil];
    [MineApis feedbackForStudentRequestWithParams:parms SuccessBlock:^(NSNumber *code, NSString *msg, id responseData) {
        StrongSelf
        [self hideLoadingHUD];
        [self.navigationController  popViewControllerAnimated:YES];

    } FailureBlock:^(NSNumber *code, NSString *msg) {
        StrongSelf
        [self showWarningHUDWithMessage:msg completion:NULL];
    }];
}

-(void)setupViews
{
    [self.bgScrollView.contentView addSubview:self.feedBackView];
    [self.bgScrollView.contentView addSubview:self.submitBtn];
}

-(void)setupLayout
{
    [self.feedBackView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.bgScrollView.contentView).offset(0);
        make.left.equalTo(self.bgScrollView.contentView).offset(-6);
        make.right.equalTo(self.bgScrollView.contentView);
        make.height.mas_equalTo(150*kScreen_Ratio_W);
    }];

    [self.submitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.feedBackView.mas_bottom).offset(40);
        make.left.equalTo(self.bgScrollView.contentView).offset(15);
        make.right.equalTo(self.bgScrollView.contentView).offset(-15);
        make.height.mas_equalTo(40);
        make.bottom.equalTo(self.bgScrollView.contentView).offset(-30 + kBottomOffset);
    }];
    
}

#pragma mark -- lazyload

-(RCDTextFeidView *)feedBackView
{
    if (!_feedBackView) {
        RCDTextFeidViewModel *model = [RCDTextFeidViewModel new];
        model.placeholder = @"请填写您的建议或意见";
        model.contentFont = UIFontSize(15);
        model.contentColor = UIColorFromHex(kColorTitle);
        model.isTextView = YES;
        _feedBackView = [[RCDTextFeidView alloc]initWithModel:model];
        [_feedBackView addTopLine];
        [_feedBackView addBottomLine];
        _feedBackView.backgroundColor = UIColorFromHex(kColorWhite);
    }
    return _feedBackView;
}

-(RCDCornerBtn *)submitBtn
{
    if (!_submitBtn) {
        _submitBtn = [RCDCornerBtn new];
        [_submitBtn setTitleString:@"提交"];
        [_submitBtn setTitleFont:16];
        _submitBtn.cornerRadius = 20;
    }
    return _submitBtn;
}

@end
